package com.quentinbeauperin.twitbird
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	import flashx.textLayout.tlf_internal;
	
	public class ObstacleGenerator extends Sprite
	{
		public var obstacle:Bitmap;
		public var obstacleArray:Array = new Array();
		public var id:int = new int();
		public var level:int = new int();
		public var count:int = new int();
		public var randomX:int = new int();
		public var curentObstacleX:int = new int();
		public var curentCount:int = new int();
		public var randomFrequencyObstacle:int = new int();
		
		public function ObstacleGenerator(id:int, lvl:int)
		{
			super();
			this.id = id;
			this.level = lvl;
		}
		
		public function createObstacle():void
		{
			if (level == 1) {
				randomFrequencyObstacle = Math.floor(Math.random()*50);
				randomX = Math.floor((Math.random()*800)+200);
				if (count % randomFrequencyObstacle == 0){			// Manage the frequency of appearance of the rings
					if (id == 1){
						if (((randomX + (count*8)) - curentObstacleX) > 150){		// Prevent having two rings too close
							obstacle = new Assets.Obstacle();
							addChild(obstacle);
							obstacleArray.push(obstacle);
							obstacle.x = randomX + (count*8);
							obstacle.y = -50 - (count*4);
							curentObstacleX = obstacle.x;
						}
					}
					else if (id == 2){
						if (((randomX + (count*12)) - curentObstacleX) > 150){		// Prevent having two obstacles too close
							obstacle = new Assets.Obstacle();
							addChild(obstacle);
							obstacleArray.push(obstacle);
							obstacle.x = randomX + (count*12);
							obstacle.y = -50 - (count*6);
							curentObstacleX = obstacle.x;
						}
					}
				}
			}
			else if (level == 5) {
				randomFrequencyObstacle = Math.floor(Math.random()*50);
				if (count % randomFrequencyObstacle == 0){			// Manage the frequency of appearance of the lianes
					if (id == 1){
						if ((count - curentCount) > 50){		// Prevent having two lianes too close
							obstacle = new Assets.Twitter1();
							addChild(obstacle);
							obstacle.x = 830 + (count*8);
							curentCount = count;
						}
					}
					else if (id == 2){
						if ((count - curentCount) > 50){		// Prevent having two lianes too close
							obstacle = new Assets.Twitter2();
							addChild(obstacle);
							obstacle.x = 830 + (count*8);
							curentCount = count;
						}
					}
				}
				
			}
		}
	}
}